﻿--[[
   @brief    tools_panel 
   @author   hqzheng
   @version  1.0
   @date     2017-04-21
--]]

tools_panel = 
{
    mainframe_dialog_id = 0;
    panel_id = 0;
    self_info_btn_id = 0;
    self_info_text_id = 0;
    msg_box_btn_id = 0;
    chat_btn_id = 0;
    self_head_ctn_id = 0;
    MENU_OFFSET_X = 15;
    MENU_OFFSET_Y = 34;
    MAX_NAME_WIDTH = 70;
    USER_INFO_BTN_OFFSET_X = 40;
    SELF_MENU_WIDTH = 150;

    init = function (parent_id, mainframe_dialog_id)
        ierd_tgp.tpf_ui.Require("offline\\self_menu.lua");
        tools_panel.mainframe_dialog_id = mainframe_dialog_id;
        tools_panel.self_info_btn_id = ui_utility.get_ctrl_id_by_path(parent_id, "CtnInfo");
        tools_panel.msg_box_btn_id = ui_utility.get_ctrl_id_by_path(parent_id, "btnMsg");
        tools_panel.chat_btn_id = ui_utility.get_ctrl_id_by_path(parent_id, "btnChat");
        tools_panel.self_head_ctn_id = ui_utility.get_ctrl_id_by_path(tools_panel.self_info_btn_id, "UserHeadCtn");

        ui_utility.setproperty_by_id(tools_panel.msg_box_btn_id, "OnClick", "tools_panel.on_msg_box_btn_click");

        -- comm_center.listen_broadcast("i_brdcst_self_info_update", tools_panel.on_handle_self_info_update);
        tools_panel.get_self_info();
    end;

    show = function (is_show)
        ui_utility.set_visible(tools_panel.panel_id, is_show);
    end;

    get_self_info = function ()
        local user_game_info = ierd_tgp.users_info.User_game_info:new_local();
        local users_info_adapter =
            base_utility.get_component_adapter("IUsers_info_module",
                "ierd_tgp.users_info.GetUsersInfoModuleAdapter();");
        if nil ~= users_info_adapter then
            users_info_adapter:get_self_game_info(user_game_info);
            -- tools_panel.set_self_head(user_game_info.head_url);
            wegame_mainframe_model.self_tgp_id = user_game_info.ullTGPID;
            wegame_mainframe_model.self_uin = user_game_info.uin;
            wegame_mainframe_model.get_big_v_info();
        end
    end;

    set_self_head = function (head_url)
--        local zInfo = TOfflineModule.zSelfInfo;
--        local   sIcon = "ONEIMAGE:";
--        if nil ~= zInfo["icon"] and TOfflineView.FileExists(zInfo["icon"]) then
--            sIcon = sIcon .. zInfo["icon"];
--        else
--            sIcon = sIcon .. "login\\icon\\icon_QQ.png";
--            TGPLog.LogE("DlgOffline", "Icon is nil.");
--        end;
--        sIcon = sIcon .. ";Circle;0;"

        ui_utility.setproperty_by_id(tools_panel.self_head_ctn_id, "Background", head_url);
    end;

    on_user_info_click = function (uilib, control_id)
        -- 显示菜单
        local menu_id = ui_utility.get_ctrl_id_by_path(tools_panel.mainframe_dialog_id, "mnShop");
        local btn_tab_ptr = ui_utility.get_ctrl_ptr_by_id(control_id);
        local mainframe_ptr = ui_utility.get_ctrl_ptr_by_id(tools_panel.mainframe_dialog_id);
        if nil == btn_tab_ptr or nil == mainframe_ptr then
            return;
        end
        local btn_tab_rc = btn_tab_ptr:GetRectEx(TRUE,TRUE);
        local mainframe_rc = mainframe_ptr:GetRectEx(TRUE,TRUE);
        local btn_tab_width = btn_tab_rc.right - btn_tab_rc.left;
        local offset_x = btn_tab_rc.left - mainframe_rc.left - (tools_panel.SELF_MENU_WIDTH - btn_tab_width) / 2;
        local offset_y = btn_tab_rc.top - mainframe_rc.top + tools_panel.MENU_OFFSET_Y;
        self_menu.show(menu_id, true, offset_x, offset_y);
    end;

    on_msg_box_btn_click = function (uilib, control_id)
        event_center.send_event(group_event.SHOW_MESSAGE_BOX_DIALOG, {});
    end;
};

